Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow rate initial support/v2 #12236

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

inashivb
Copy link
Member

@inashivb inashivb commented Dec 5, 2024

Link to ticket: https://redmine.openinfosecfoundation.org/issues/7438

SV_BRANCH=OISF/suricata-verify#2164

Previous PR: #12123

Changes since v1:

  • split out the flow.rate keyword changes
  • added user docs
  • review comments addressed

This is to allow a way to match on the rate of the flow through rule
language. This serves as a trivial first step to a more elaborate path
to defining and detecting elephant flows.

Feature 7438

Signature example::

pass tcp any any -> any any (msg:"Flow rate higher than 50kbps"; flow.rate:>50kb; sid:1; rev:1;)
Copy link
Member Author

@inashivb inashivb Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of mismatching units. Considering keeping the initial syntax something like flow.rate:>500kb,10 where 500kb is the number of bytes and 10 the seconds with which the rate will be calculated.

Copy link
Member Author

@inashivb inashivb Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other ideas, none of which I'm a fan of:

flow.rate: 50kbps
flow.rate: 50kb,10  # document that first arg is bytes and second one the number of seconds
flow.rate: 50kb,10s
flow.rate: 50kb  # document that this means 50kbytes per second
flow.rate: bytes 50kb, seconds 10  # inspired by threshold keyword

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Between those, I like:

flow.rate: 50kb,10s

The most, I think. I imagine that any format would need documenting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may also want packets instead of bytes like flow.rate: packets 50, seconds 10

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you also want milliseconds ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you also want milliseconds ?

@catenacyber I don't know yet. Do you think somebody might want to express rate as 10k bytes in 5ms?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know either, but maybe more granularity/expressivity is always better ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Shall keep that in mind. Thanks a lot for your valuable feedback, both! 🙇🏽‍♀️

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 76.74419% with 10 lines in your changes missing coverage. Please review.

Project coverage is 83.18%. Comparing base (b58b886) to head (8ffd979).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #12236   +/-   ##
=======================================
  Coverage   83.18%   83.18%           
=======================================
  Files         912      913    +1     
  Lines      257169   257209   +40     
=======================================
+ Hits       213914   213962   +48     
+ Misses      43255    43247    -8     
Flag Coverage Δ
fuzzcorpus 60.99% <18.60%> (-0.02%) ⬇️
livemode 19.41% <18.60%> (-0.01%) ⬇️
pcap 44.40% <18.60%> (+0.02%) ⬆️
suricata-verify 62.77% <76.74%> (-0.01%) ⬇️
unittests 59.18% <18.60%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

}

uint64_t age = SCTIME_SECS(p->flow->lastts) - SCTIME_SECS(p->flow->startts);
uint64_t rate = (p->flow->tosrcbytecnt + p->flow->todstbytecnt) / age;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch for division by zero ;-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed. an embarrassing mistake. thank you!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also shows lack of tests btw. Something like this should have easily been caught

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants